﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BlueCMS.Core.Data.Query.Conditions
{
    public abstract class ConditionBase 
    {
        public ConditionBase Next { get; set; }

        public ConditionBase StartGroup()
        {
            Next = new StartNode();
            return Next;
        }

        public ConditionBase EndGroup()
        {
            Next = new EndNode();
            return Next;
        }

        public ConditionBase And()
        {
            Next = new LogicNode(LogicNodeType.And);
            return Next;
        }

        public ConditionBase Or()
        {
            Next = new LogicNode(LogicNodeType.Or);
            return Next;
        }

        public ConditionBase In()
        {
            Next = new ConditionNode(ConditionNodeType.In);
            return Next;
        }

        public ConditionBase NotIn()
        {
            Next = new ConditionNode(ConditionNodeType.NotIn);
            return Next;
        }

        public ConditionBase Equals()
        {
            Next = new ConditionNode(ConditionNodeType.Equals);
            return Next;
        }

        public ConditionBase NotEquals()
        {
            Next = new ConditionNode(ConditionNodeType.NotEquals);
            return Next;
        }

        public ConditionBase GreaterThan()
        {
            Next = new ConditionNode(ConditionNodeType.GreaterThan);
            return Next;
        }

        public ConditionBase GreaterThanOrEqual()
        {
            Next = new ConditionNode(ConditionNodeType.GreaterThanOrEqual);
            return Next;
        }

        public ConditionBase LessThan()
        {
            Next = new ConditionNode(ConditionNodeType.LessThan);
            return Next;
        }

        public ConditionBase LessThanOrEqual()
        {
            Next = new ConditionNode(ConditionNodeType.LessThanOrEqual);
            return Next;
        }

        public ConditionBase Like()
        {
            Next = new ConditionNode(ConditionNodeType.Like);
            return Next;
        }

        public ConditionBase NotLike()
        {
            Next = new ConditionNode(ConditionNodeType.NotLike);
            return Next;
        }

        public ConditionBase IsNull()
        {
            Next = new ConditionNode(ConditionNodeType.IsNull);
            return Next;
        }

        public ConditionBase IsNotNull()
        {
            Next = new ConditionNode(ConditionNodeType.IsNotNull);
            return Next;
        }

        public ConditionBase SubSelect(Action<SelectQuery> subquery)
        {
            throw new NotImplementedException();
        }

        public ConditionBase Start()
        {
            Next = new StartNode();
            return Next;
        }

        public ConditionBase Aggregate(string clause)
        {
            Next = new AggregateNode(clause);
            return Next;
        }

        public ConditionBase Column(string name)
        {
            Next = new ColumnNode(name);
            return Next;
        }

        public ConditionBase Constant(object value)
        {
            Next = new ConstantNode(value);
            return Next;
        }

        public ConditionBase Parameter(object value)
        {
            Next = new ParameterNode(value);
            return Next;
        }

        public ConditionBase Parameter(object value, string name)
        {
            Next = new ParameterNode(value, name);
            return Next;
        }

        public ConditionBase Exists(Action<SelectQuery> subquery)
        {
            Next = new ExistsNode(ExistsNodeType.Exists, subquery);
            return Next;
        }

        public ConditionBase NotExists(Action<SelectQuery> subquery)
        {
            Next = new ExistsNode(ExistsNodeType.NotExists, subquery);
            return Next;
        }
    }
}
